import { View, Text, Navigator, Button } from "@tarojs/components";
import Taro, { useLoad } from "@tarojs/taro";
import "./index.scss";

export default function PageRouter() {
  useLoad(() => {
    console.log("Page loaded.");
  });

  function goToDetail01() {
    Taro.navigateTo({
      url: "/pages/detail01/index",
    });
  }
  function goToDetail02() {
    Taro.redirectTo({
      url: "/pages/detail01/index",
    });
  }
  function goToDetail03() {
    Taro.switchTab({
      url: "/pages/category/index",
    });
  }

  return (
    <View className="PageRouter">
      <Text>1.页面跳转（组件）</Text>
      <Navigator url="/pages/detail01/index" openType="navigate">
        <Button>goToDetail01 navigate </Button>
      </Navigator>
      <Navigator url="/pages/detail01/index" openType="redirect">
        <Button>goToDetail01 redirect</Button>
      </Navigator>
      <Navigator url="/pages/category/index" openType="switchTab">
        <Button>goToDetail01 switchTab</Button>
      </Navigator>

      <View>2.页面跳转（API）</View>
      <Button onClick={goToDetail01}>goToDetail01 navigate</Button>
      <Button onClick={goToDetail02}>goToDetail01 redirect</Button>
      <Button onClick={goToDetail03}>goToDetail01 switchTab</Button>
    </View>
  );
}
